#!/bin/bash
# /etc/init.d/clock
### BEGIN INIT INFO
# Provides: embbnux
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: clock initscript
# Description: This service is used to manage a led
### END INIT INFO

case "$1" in
    start)
        echo "Starting Clock"
        sudo pigpiod
        while [ 1 ]
        do
            sudo python3 /home/pi/raspberry-clock/main.py
        done
        ;;
    stop)
        echo "Stopping Clock"
        #killall main.py
        kill $(ps aux | grep -m 1 'python3 /home/pi/raspberry-clock/main.py' | awk '{ print $2 }')
	#sudo pigpio -x -1
        ;;
    restart)
        echo "Restarting Clock"
        kill $(ps aux | grep -m 1 'python3 /home/pi/raspberry-clock/main.py' | awk '{ print $2 }')kill $(ps aux | grep -m 1 'python3 /home/pi/raspberry-clock/main.py' | awk '{ print $2 }')
        sudo python3 /home/pi/raspberry-clock/main.py &
        ;;
    *)
        echo "Usage: service clock start|stop"
        exit 1
        ;;
esac
exit 0
